//
//  ConReportViewController.m
//  Shengzhuli
//
//  Created by FXGuo on 2017/8/9.
//  Copyright © 2017年 kamangkeji. All rights reserved.
//

#import "ConReportViewController.h"
#import "MBProgressHUD+MJ.h"
#import "NSString+Valid.h"
#import "SZLAccountHelper.h"
#import "ClubNetwork.h"

@interface ConReportViewController ()

@property (weak, nonatomic) IBOutlet UITextField *nameField;
@property (weak, nonatomic) IBOutlet UITextField *tellField;

@end

@implementation ConReportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"活动报名";
    self.view.backgroundColor = RGBColor(239, 239, 244);
    [self configNaviColor];
}
- (void)configNaviColor
{
    CGSize imageSize = CGSizeMake(320,64);
    UIGraphicsBeginImageContextWithOptions(imageSize,0, [UIScreen mainScreen].scale);
    [[UIColor whiteColor] set];
    UIRectFill(CGRectMake(0,0, imageSize.width, imageSize.height));
    UIImage *pressedColorImg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.navigationController.navigationBar setBackgroundImage:pressedColorImg forBarMetrics:UIBarMetricsDefault];
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:20]};
    
}

- (UIBarButtonItem *)customBackItemWithTarget:(id)target
                                       action:(SEL)action
{
    UIButton *backBtn = [[UIButton alloc]init];
    backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [backBtn setBackgroundImage:[UIImage imageNamed:@"ic_left_back"] forState:UIControlStateNormal];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"ic_left_back_select"] forState:UIControlStateHighlighted];
    [backBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [backBtn sizeToFit];
    backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    return [[UIBarButtonItem alloc]initWithCustomView:backBtn];
}

- (IBAction)reportClick:(UIButton *)btn
{
    if (self.nameField.text.length<1) {
        [MBProgressHUD showError:@"请输入姓名"];
        return;
    }
    if (![self.tellField.text isValidMobileNumber]) {
        [MBProgressHUD showError:@"请输入正确的手机号"];
        return;
    }
    NSMutableDictionary *parame = [NSMutableDictionary dictionary];
    parame[@"token"] = [SZLAccountHelper shareInstance].token;
    parame[@"activityId"] = @(self.ID);
    parame[@"registrationName"] = self.nameField.text;
    parame[@"registrationPhone"] = self.tellField.text;
    [self showClearBgWaiter];
    [ClubNetwork nearActivityReportWithParame:parame response:^(BOOL success, NSString *msg) {
        [self hideWaiter];
        if (success) {
            [MBProgressHUD showSuccess:@"报名成功"];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [self.navigationController popViewControllerAnimated:YES];
            });
        }else {
            [MBProgressHUD showError:msg];
        }
    }];
}



@end
